﻿#region Imports
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using CommonUtilities.Enums;
using CommonUtilities.Extensions;
using PatternLocker.Utils;
#endregion

namespace PatternLocker.Converters
{
    public class InnerCircleSizeConverter : IValueConverter
    {
        #region Declarations
        public const int sizeOffset = 20;
        #endregion

        #region Converter methods
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double offset = GetOffset(parameter);
            if (targetType == typeof(CornerRadius))
            {
                Dictionary<eUIDirection, double> dictDirection = new Dictionary<eUIDirection, double>();
                dictDirection.Add(eUIDirection.All, offset);

                return ((CornerRadius)value).UpdateRadius(true, dictDirection);
            }
            else
                return (double)value - GetOffset(parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double offset = GetOffset(parameter);
            if (targetType == typeof(CornerRadius))
            {
                Dictionary<eUIDirection, double> dictDirection = new Dictionary<eUIDirection, double>();
                dictDirection.Add(eUIDirection.All, offset);

                return ((CornerRadius)value).UpdateRadius(false, dictDirection);
            }
            else
                return (double)value + offset;
        }
        #endregion

        #region Methods
        public double GetOffset(object parameter)
        {
            double offset = sizeOffset;
            if (!parameter.IsNull())
                if (parameter.IsNumeric())
                    offset = System.Convert.ToDouble(parameter);

            return offset;
        }
        #endregion
    }
}
